package com.admin.web.task;


import com.bayss.core.entity.station.Station;
import com.bayss.core.enums.HandleCode;
import com.bayss.core.model.ShowOrder;
import com.bayss.core.service.order.OrderService;
import com.bayss.core.service.station.StationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.List;

/**
 * @author yangjian9
 */
@Slf4j
@Configuration
@EnableScheduling
public class TempJob {

    private OrderService orderService;

    private StationService stationService;

    @Autowired
    public void setTortLogService(OrderService orderService) {
        this.orderService = orderService;
    }

    @Autowired
    public void setStationService(StationService stationService) {
        this.stationService = stationService;
    }

    @Scheduled(cron = "0 */1 * * * ?") // 上线后注释就行， 应该doko调用给厨师出单。   没注释就丢单了  TODO
    private void ValidTortLog() {
        List<Station> stations = stationService.get();

        for (Station station : stations) {
            List<ShowOrder> showOrders = orderService.getOrdersByPool(station.getId(), HandleCode.NEW, 0L, 10);
            if (showOrders == null) {
                continue;
            }
            for (ShowOrder showOrder : showOrders) {
                orderService.submit(showOrder.getId());
            }
        }
    }

}
